﻿//Copyright (c) 2010 William Liu, Enoch Ye
//William Liu <william.lyz@gmail.com>
//Enoch Ye <moonlight.enoch@gmail.com>

//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at

//       http://www.apache.org/licenses/LICENSE-2.0

//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GBG_DBM.Support.DAL.Entities;
using GBG_DBM.Support.DAL;

namespace GBG_DBM.UI
{
    public partial class Package_UI : Form
    {
        
        private Packaging _Package = new Packaging();
        private DBAccessory _DBAccessory = new DBAccessory();
        public Package_UI()
        {
            InitializeComponent();
        }
        public Package_UI(Packaging Package) 
        {
            InitializeComponent();
            _Package = Package;
            DataBind();
        }
        private void DataBind() 
        {
            txtPackage.Text = _Package.Package.ToString();
            txtPackagePrice.Text = Convert.ToString(_Package.Price);
        }
        private void btnPackageCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnPackageOk_Click(object sender, EventArgs e)
        {
            if (txtPackage.Text.Length > 0 || txtPackagePrice.Text.Length > 0)
            {
                _Package.Package = Convert.ToInt32(txtPackage.Text);
                _Package.Price = Convert.ToSingle(txtPackagePrice.Text);
                _DBAccessory.setPackage(_Package);
                this.Close();
            }
            else
            {
                _Package.Package = Convert.ToInt32(txtPackage.Text);
                _Package.Price = Convert.ToSingle(txtPackagePrice.Text);
                _DBAccessory.addPackege(_Package);
                this.Close();
            }
        }

        private void Package_UI_FormClosing(object sender, FormClosingEventArgs e)
        {
            Main_UI main = Main_UI.getInstance();
            main.activateButton();
        }
    }
}
